SET client_encoding = 'UTF8';

CREATE PROCEDURAL LANGUAGE plpgsql;

ALTER PROCEDURAL LANGUAGE plpgsql OWNER TO postgres;

SET search_path = public, pg_catalog;

SET default_tablespace = '';

SET default_with_oids = false;



CREATE TABLE TAUDITORIO (
    nCodAud serial NOT NULL,
    cNomAud character varying(45) NOT NULL,
    tUbiAud text,
    nCodUsu integer DEFAULT 999999999 NOT NULL,
    dModUsu timestamp without time zone DEFAULT now() NOT NULL
);
ALTER TABLE TAUDITORIO
    ADD CONSTRAINT TAUDITORIO_pk PRIMARY KEY (nCodAud);

COMMENT ON COLUMN TAUDITORIO.cNomAud IS 'Nombre del auditorio';
COMMENT ON COLUMN TAUDITORIO.tUbiAud IS 'Ubicacion del auditorio';


CREATE TABLE TAUDI_EVE (
    nCodAudEve serial NOT NULL,
    nCodUsu integer DEFAULT 999999999 NOT NULL,
    dModUsu timestamp without time zone DEFAULT now() NOT NULL,
    nCodAud integer NOT NULL,
    nCodEve integer NOT NULL
);
ALTER TABLE TAUDI_EVE
    ADD CONSTRAINT TAUDI_EVE_pk PRIMARY KEY (nCodAudEve);


CREATE TABLE TEVENTO (
    nCodEve serial NOT NULL,
    cNomEve character varying(45) NOT NULL,
    tDesEve text,
    tUbiEve text,
    tDireEve text,
    nCodUsu integer DEFAULT 999999999 NOT NULL,
    dModUsu timestamp without time zone DEFAULT now() NOT NULL
);
ALTER TABLE TEVENTO
    ADD CONSTRAINT TEVENTO_pk PRIMARY KEY (nCodEve);

COMMENT ON COLUMN TEVENTO.cNomEve IS 'Nombre del evento';
COMMENT ON COLUMN TEVENTO.tDesEve IS 'Descripcion del evento';
COMMENT ON COLUMN TEVENTO.tUbiEve IS 'Ubicacion del evento';
COMMENT ON COLUMN TEVENTO.tDireEve IS 'Direccion del evento';



CREATE TABLE TGASTO (
    nCodGas serial NOT NULL,
    cNumGas character varying(15) NOT NULL,
    cConGas character varying(45) NOT NULL,
    cDesGas character varying(45),
    dFecGas date DEFAULT now() NOT NULL,
    cTipGas character(2) NOT NULL,
    nCodUsu integer DEFAULT 999999999 NOT NULL,
    dModUsu timestamp without time zone DEFAULT now() NOT NULL,
    nCodEve integer NOT NULL
);
ALTER TABLE TGASTO
    ADD CONSTRAINT TGASTO_pk PRIMARY KEY (nCodGas);

COMMENT ON COLUMN TGASTO.cNumGas IS 'Numero del comprobante del gasto';
COMMENT ON COLUMN TGASTO.cConGas IS 'Concepto del gasto';
COMMENT ON COLUMN TGASTO.cDesGas IS 'Descripcion del gasto';
COMMENT ON COLUMN TGASTO.dFecGas IS 'Fecha del gasto';
COMMENT ON COLUMN TGASTO.cTipGas IS 'Tipo del gasto';


CREATE TABLE TINSCRIPCION (
    nCodIns serial NOT NULL,
    cGraAca character varying(45),
    cInsTit character varying(45),
    tObs text,
    lAct boolean DEFAULT false NOT NULL,
    cTipIns character(2),
    lMatEnt boolean DEFAULT false NOT NULL,
    lCerEve boolean DEFAULT false NOT NULL,
    nCodUsu integer DEFAULT 999999999 NOT NULL,
    dModUsu timestamp without time zone DEFAULT now() NOT NULL,
    nCodEve integer NOT NULL,
    nCodPer integer NOT NULL
);
ALTER TABLE TINSCRIPCION
    ADD CONSTRAINT TINSCRIPCION_pk PRIMARY KEY (nCodIns);

COMMENT ON COLUMN TINSCRIPCION.cGraAca IS 'Grado academico del asistente para esa inscripcion';
COMMENT ON COLUMN TINSCRIPCION.cInsTit IS 'Institucion de la que proviene el asistente para esa inscripcion';
COMMENT ON COLUMN TINSCRIPCION.tObs IS 'Observaciones';
COMMENT ON COLUMN TINSCRIPCION.lAct IS 'Si la inscripcion esta activa o no, por defecto falso';
COMMENT ON COLUMN TINSCRIPCION.cTipIns IS 'Tipo de la inscripcion: Ponente, asistente';
COMMENT ON COLUMN TINSCRIPCION.lMatEnt IS 'Material entregado, por defecto falso';
COMMENT ON COLUMN TINSCRIPCION.lCerEve IS 'Certificado del evento entregado, por defecto falso';


CREATE TABLE TMAESTRA (
    cCodTip character(2) NOT NULL,
    cDesTip character varying(45),
    nCodUsu integer DEFAULT 999999999 NOT NULL,
    dModUsu timestamp without time zone DEFAULT now() NOT NULL
);
ALTER TABLE TMAESTRA
    ADD CONSTRAINT TMAESTRA_pk PRIMARY KEY (cCodTip);

COMMENT ON COLUMN TMAESTRA.cCodTip IS 'Clave para la tabla';
COMMENT ON COLUMN TMAESTRA.cDesTip IS 'Descripcion del tipo';


CREATE TABLE TPERFIL (
    nCodPerf serial NOT NULL,
    cDesPerf character varying(45) NOT NULL,
    nCodUsu integer DEFAULT 999999999 NOT NULL,
    dModUsu timestamp without time zone DEFAULT now() NOT NULL
);
ALTER TABLE TPERFIL
    ADD CONSTRAINT TPERFIL_pk PRIMARY KEY (nCodPerf);

COMMENT ON COLUMN TPERFIL.cDesPerf IS 'Descripcion del perfil';


CREATE TABLE TPERFIL_EVENTO_PERSONA (
    nCodPerfEvePer serial NOT NULL,
    nCodUsu integer DEFAULT 999999999 NOT NULL,
    dModUsu timestamp without time zone DEFAULT now() NOT NULL,
    nCodPerf integer NOT NULL,
    nCodEve integer NOT NULL,
    nCodPer integer NOT NULL
);
ALTER TABLE TPERFIL_EVENTO_PERSONA
    ADD CONSTRAINT TPERFIL_EVENTO_PERSONA_pk PRIMARY KEY (nCodPerfEvePer);


CREATE TABLE TPERSONA (
    cNumDoc text NOT NULL,
    cTipDoc character(2) NOT NULL,
    cNomPer character varying(45),
    cApePat character varying(20) NOT NULL,
    nCodPer serial NOT NULL,
    cApeMat character varying(20),
    dFecNac date,
    cSexo character(2),
    cEmail character varying(45) NOT NULL,
    tDirec text,
    cCel character varying(12),
    cPassword character varying(12) NOT NULL,
    nCodUsu integer DEFAULT 999999999 NOT NULL,
    dModUsu timestamp without time zone DEFAULT now() NOT NULL
);
ALTER TABLE TPERSONA
    ADD CONSTRAINT TPERSONA_pk PRIMARY KEY (nCodPer);

COMMENT ON COLUMN TPERSONA.cNumDoc IS 'Numero de documento';
COMMENT ON COLUMN TPERSONA.cTipDoc IS 'Tipo de documento';
COMMENT ON COLUMN TPERSONA.cNomPer IS 'Nombre de la persona';
COMMENT ON COLUMN TPERSONA.cApePat IS 'Apellido paterno';
COMMENT ON COLUMN TPERSONA.cApeMat IS 'Apellido materno';
COMMENT ON COLUMN TPERSONA.dFecNac IS 'Fecha de nacimiento';
COMMENT ON COLUMN TPERSONA.cSexo IS 'Sexo de la persona';
COMMENT ON COLUMN TPERSONA.cEmail IS 'Email de la persona, la cual sera usada como nombre de usuario';
COMMENT ON COLUMN TPERSONA.tDirec IS 'Direccion de la persona';
COMMENT ON COLUMN TPERSONA.cCel IS 'Telefono del usuario';
COMMENT ON COLUMN TPERSONA.cPassword IS 'Password de la persona para validarse en el sistema';
COMMENT ON COLUMN TPERSONA.nCodUsu IS 'Codigo del usuario que crea, modifica el registro';
COMMENT ON COLUMN TPERSONA.dModUsu IS 'Fecha en la que se crea o modifica el registro, por defecto es la hora actual del sistema.';


CREATE TABLE TPONENCIA (
    nCodPon serial NOT NULL,
    cNomPon character varying(80) NOT NULL,
    nNumPon integer NOT NULL,
    nCodUsu integer DEFAULT 999999999 NOT NULL,
    dModUsu timestamp without time zone DEFAULT now() NOT NULL,
    nCodAudEve integer NOT NULL,
    nCodSes integer NOT NULL
);
ALTER TABLE TPONENCIA
    ADD CONSTRAINT TPONENCIA_pk PRIMARY KEY (nCodPon);

COMMENT ON COLUMN TPONENCIA.cNomPon IS 'Nombre de la ponencia';
COMMENT ON COLUMN TPONENCIA.nNumPon IS 'Numero de la ponencia';


CREATE TABLE TPON_INS (
    nCodPonIns serial NOT NULL,
    lAsisten boolean DEFAULT false NOT NULL,
    nCodUsu integer DEFAULT 999999999 NOT NULL,
    dModUsu timestamp without time zone DEFAULT now() NOT NULL,
    nCodIns integer NOT NULL,
    nCodPon integer NOT NULL
);
ALTER TABLE TPON_INS
    ADD CONSTRAINT TPON_INS_pk PRIMARY KEY (nCodPonIns);

COMMENT ON COLUMN TPON_INS.lAsisten IS 'Asistencia de la inscripcion a la ponencia, por defecto falso';


CREATE TABLE TSESION (
    nCodSes serial NOT NULL,
    cTipSes character(2) NOT NULL,
    nCodUsu integer DEFAULT 999999999 NOT NULL,
    dModUsu timestamp without time zone DEFAULT now() NOT NULL,
    nCodEve integer NOT NULL
);
ALTER TABLE TSESION
    ADD CONSTRAINT TSESION_pk PRIMARY KEY (nCodSes);

COMMENT ON COLUMN TSESION.cTipSes IS 'Tipo de sesion';


CREATE TABLE TTAREA (
    nCodTar serial NOT NULL,
    cDesTar character varying(45),
    cLinkTar character varying(45),
    cAction character varying(45),
    nCodUsu integer DEFAULT 999999999 NOT NULL,
    dModUsu timestamp without time zone DEFAULT now() NOT NULL
);
ALTER TABLE TTAREA
    ADD CONSTRAINT TTAREA_pk PRIMARY KEY (nCodTar);

COMMENT ON COLUMN TTAREA.cDesTar IS 'Descripcion de la tarea';
COMMENT ON COLUMN TTAREA.cLinkTar IS 'Link de la tarea';
COMMENT ON COLUMN TTAREA.cAction IS 'Accion struts de la tarea';


CREATE TABLE TTAR_PERF (
    nCodTarPerf serial NOT NULL,
    nCodEve integer NOT NULL,
    nCodUsu integer DEFAULT 999999999 NOT NULL,
    dModUsu timestamp without time zone DEFAULT now() NOT NULL,
    nCodTar integer NOT NULL,
    nCodPerf integer NOT NULL
);
ALTER TABLE TTAR_PERF
    ADD CONSTRAINT TTAR_PERF_pk PRIMARY KEY (nCodTarPerf);

COMMENT ON COLUMN TTAR_PERF.nCodEve IS 'Codigo del evento';


--
-- TOC entry 1967 (class 2606 OID 17243)
-- Dependencies: 1554 1577 1933
-- Name: TAUDI_EVE_TPONENCIA; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE TPONENCIA
    ADD CONSTRAINT TAUDI_EVE_TPONENCIA FOREIGN KEY (nCodAudEve) REFERENCES TAUDI_EVE(nCodAudEve) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1960 (class 2606 OID 17248)
-- Dependencies: 1556 1554 1935
-- Name: TEVENTO_TAUDI_EVE; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE TAUDI_EVE
    ADD CONSTRAINT TEVENTO_TAUDI_EVE FOREIGN KEY (nCodEve) REFERENCES TEVENTO(nCodEve) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1961 (class 2606 OID 17253)
-- Dependencies: 1556 1559 1935
-- Name: TEVENTO_TGASTO; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE TGASTO
    ADD CONSTRAINT TEVENTO_TGASTO FOREIGN KEY (nCodEve) REFERENCES TEVENTO(nCodEve) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1962 (class 2606 OID 17258)
-- Dependencies: 1556 1563 1935
-- Name: TEVENTO_TINSCRIPCION; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE TINSCRIPCION
    ADD CONSTRAINT TEVENTO_TINSCRIPCION FOREIGN KEY (nCodEve) REFERENCES TEVENTO(nCodEve) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1964 (class 2606 OID 17263)
-- Dependencies: 1935 1556 1571
-- Name: TEVENTO_TPERFIL_EVENTO_PERSONA; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE TPERFIL_EVENTO_PERSONA
    ADD CONSTRAINT TEVENTO_TPERFIL_EVENTO_PERSONA FOREIGN KEY (nCodEve) REFERENCES TEVENTO(nCodEve) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1971 (class 2606 OID 17268)
-- Dependencies: 1935 1584 1556
-- Name: TEVENTO_TSESION; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE TSESION
    ADD CONSTRAINT TEVENTO_TSESION FOREIGN KEY (nCodEve) REFERENCES TEVENTO(nCodEve) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1969 (class 2606 OID 17273)
-- Dependencies: 1939 1581 1563
-- Name: TINSCRIPCION_TPON_INS; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE TPON_INS
    ADD CONSTRAINT TINSCRIPCION_TPON_INS FOREIGN KEY (nCodIns) REFERENCES TINSCRIPCION(nCodIns) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1965 (class 2606 OID 17278)
-- Dependencies: 1943 1566 1571
-- Name: TPERFIL_TPERFIL_EVENTO_PERSONA; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE TPERFIL_EVENTO_PERSONA
    ADD CONSTRAINT TPERFIL_TPERFIL_EVENTO_PERSONA FOREIGN KEY (nCodPerf) REFERENCES TPERFIL(nCodPerf) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1972 (class 2606 OID 17283)
-- Dependencies: 1943 1566 1591
-- Name: TPERFIL_TTAR_PERF; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE TTAR_PERF
    ADD CONSTRAINT TPERFIL_TTAR_PERF FOREIGN KEY (nCodPerf) REFERENCES TPERFIL(nCodPerf) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1963 (class 2606 OID 17288)
-- Dependencies: 1563 1947 1573
-- Name: TPERSONA_TINSCRIPCION; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE TINSCRIPCION
    ADD CONSTRAINT TPERSONA_TINSCRIPCION FOREIGN KEY (nCodPer) REFERENCES TPERSONA(nCodPer) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1966 (class 2606 OID 17293)
-- Dependencies: 1571 1573 1947
-- Name: TPERSONA_TPERFIL_EVENTO_PERSONA; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE TPERFIL_EVENTO_PERSONA
    ADD CONSTRAINT TPERSONA_TPERFIL_EVENTO_PERSONA FOREIGN KEY (nCodPer) REFERENCES TPERSONA(nCodPer) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1970 (class 2606 OID 17298)
-- Dependencies: 1581 1949 1577
-- Name: TPONENCIA_TPON_INS; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE TPON_INS
    ADD CONSTRAINT TPONENCIA_TPON_INS FOREIGN KEY (nCodPon) REFERENCES TPONENCIA(nCodPon) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1968 (class 2606 OID 17303)
-- Dependencies: 1577 1953 1584
-- Name: TSESION_TPONENCIA; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE TPONENCIA
    ADD CONSTRAINT TSESION_TPONENCIA FOREIGN KEY (nCodSes) REFERENCES TSESION(nCodSes) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1973 (class 2606 OID 17308)
-- Dependencies: 1586 1955 1591
-- Name: TTAREA_TTAR_PERF; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE TTAR_PERF
    ADD CONSTRAINT TTAREA_TTAR_PERF FOREIGN KEY (nCodTar) REFERENCES TTAREA(nCodTar) ON UPDATE CASCADE ON DELETE CASCADE;

